package com.gali.shop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.gali.shop.pojo.TbBrand;
import com.gali.shop.service.TbBrandService;
import com.gali.shop.utils.PageResult;
import com.gali.shop.utils.QueryBeanPage;
import com.gali.shop.utils.ResultUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author gali
 * @description:
 * @date 2022/6/28 10:55
 */
@RestController
@RequestMapping("/brand")
public class TbBrandController {

    @Reference
    private TbBrandService brandService;

    @RequestMapping("/findOne")
    public ResultUtil findOne(@RequestParam("id") Long id){
     return brandService.findOne(id);
    }
    @RequestMapping("/findAll")
    public PageResult findAll(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        QueryBeanPage queryBeanPage = new QueryBeanPage();
        queryBeanPage.setPageNum(pageNum);
        queryBeanPage.setPageSize(pageSize);
        return brandService.findAll(queryBeanPage);
    }
    @RequestMapping("/addBrand")
    public ResultUtil addBrand(@RequestBody TbBrand tbBrand){
       return brandService.addBrand(tbBrand);
    }
    @RequestMapping("/deleteBrand")
    public ResultUtil deleteBrand(@RequestParam("ids") Long []ids){
       return brandService.removeBrand(ids);
    }
    @RequestMapping("/updateBrand")
    public ResultUtil updateBrand(@RequestBody TbBrand tbBrand){
        return brandService.reviseBrand(tbBrand);
    }
    @RequestMapping("/selectKeyWord")
    public PageResult selectKeyWord(@RequestParam Integer pageNum,@RequestParam Integer pageSize, @RequestBody TbBrand tbBrand){
        QueryBeanPage queryBeanPage = new QueryBeanPage();
        queryBeanPage.setPageNum(pageNum);
        queryBeanPage.setPageSize(pageSize);
        return brandService.selectKeyWord(queryBeanPage,tbBrand);
    }
    @RequestMapping("/selectOptionList")
    public List<Map> selectOptionList(){
        return brandService.selectBrand();
    }
}
